home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-08-28 | 10.2 KB | 449 lines | [TEXT/KAHL] |
- /**********************************************************************************
-
- Assembly.c
-
- This file contains the three assembly files, (cksum.a,
- elistener.a, and listener.a) as one C file, so that the
- assembly can be put into the project file as in-line
- assembly code.
- - Rob Clawson, 8/17/90
-
- ***********************************************************************************/
-
-
- /***********************************************************************************
- cksum.a
- ***********************************************************************************/
-
- /*
-
- blanks off
- case on */
-
- /************************************************************************************/
-
- /*; public _ipcheck,_tcpcheck
- ipcheck PROC EXPORT ; (integer) sum = ipcheck(buf:Ptr, wdcnt:integer) */
- ipcheck(void *param1,int param2)
- {
- asm {
- clr.l d1
- move.l 8(sp),d1 ; move w on Aztec (16b) move l on MPW (32b)
- move.l 4(sp),a0
- subq.l #1,d1
- clr.l d0
- again
- add.w (a0)+,d0
- bcc.s nocar
- addq.w #1,d0
- nocar
- dbra d1,again
- andi.w #$0ffff,d0
- eori.w #$0ffff,d0
- rts
- }
- /* ENDPROC */
-
- } /* End ipcheck */
-
- /**********************************************************************************/
- /*
- tcpcheck PROC EXPORT ; (integer) sum = tcpcheck(phd: Ptr,buf:Ptr, btcnt:integer) */
- tcpcheck(void *param1, void *param2, int param3)
- {
- asm {
- clr.l d1
- clr.l d0
- move.l 4(sp),a0
- moveq #5,d1
- again2 ; check the 12 byte pseudo header.
- add.w (a0)+,d0
- bcc.s nocar2
- addq.w #1,d0
- nocar2
- dbra d1,again2
-
- move.l 8(sp),a0
- move.l 12(sp),d1 ; move w on Aztec (16b) move l on MPW (32b)
- asr.w #1,d1
- bcc.s onward
- move.l 12(sp),d2
- clr.b 0(a0,d2)
- addq.w #1,d1
- onward
- subq.w #1,d1
- again3
- add.w (a0)+,d0
- bcc.s nocar3
- addq.w #1,d0
- nocar3
-
- dbra d1,again3
- tcpend
- andi.w #$0ffff,d0
- eori.w #$0ffff,d0
- rts
- }
- /* ENDPROC
-
- END
- */
- } /* End tcpcheck */
-
- /***********************************************************************************
- elistener.a
- ***********************************************************************************/
- /*; The NCSA Socket Listener. For use with NCSA's TCP/IP Implementation
- ; developed in 1986 by Tim Krauskopf and Gaige Paulsen.
- ;
- ;
- ; Well, that nutty Gaige guy decided one day to make this little pile
- ; work with EtherTalk....... here are the results.
- ;
- ; The Socket Listener is passed as a parameter to the DDPOpen Call for
- ; AppleTalk. At this time, all packets received for that socket are passed
- ; to said socket listener instead of causing events.
- ;
-
- blanks off
- case on
- */
- /**** Should I make all of these #defines? ****/
-
- #define AB_IP_Socket 72
- #define ETtype -2
- #define ETfrom -8
- #define ETto -14
- #define ETaddr1 -6
- #define ETaddr2 -10
- #define ETaddr3 -14
- #define ET_IP $0800
- #define ET_ARP $0806
- #define ET_RARP $8035
- #define dLAYER 16
- #define IPProt -2
- #define IPLen -16
- #define bufpt 0
- #define bufread 4
- #define buforg 8
- #define bufend 12
- #define bufbig 16
- #define buflim 18
-
- /* This is just the old stuff */
- AB_IP_Socket EQU 72
- ETtype EQU -2 Relative to the wild and wonderful A3
- ETfrom EQU -8 Ditto, but prolly unused
- ETto EQU -14 ditto that previous ditto
- ETaddr1 EQU -6
- ETaddr2 EQU -10
- ETaddr3 EQU -14
- ET_IP EQU $0800
- ET_ARP EQU $0806
- ET_RARP EQU $8035
- dLAYER EQU 16 Get the size from C please! (Just did....)
- IPProt EQU -2 Not Actually the IP protocol --dlayer....
- IPLen EQU -16 I Think
- bufpt EQU 0
- bufread EQU 4
- buforg EQU 8
- bufend EQU 12
- bufbig EQU 16
- buflim EQU 18 */
- /*;
- ;
- ; PUBLIC _ETListen,_ETInitBufPtr
- ;
-
- _Debugger OPWORD $A9FF
-
- ETnastyhack PROC EXPORT
-
- DEAF DC.W 0
- bufptrs DC.L 0
- badrecv DC.L 0
- */
- EXPORT ETInitBufPtr
- EXPORT ETListen
- EXPORT ETdeafreset
-
- /*ETdeafreset */
- ETdeafreset()
- {
- asm {
- LEA DEAF,A0 return deaf flag value
- MOVEQ.L #0,D0
- MOVEQ.L #0,D1
- MOVE.W 0(A0),D0 return DEAF value
- MOVE.W D1,0(A0) set deaf back off
- RTS
- }
- } /* End ETdeafreset */
-
- /*ETInitBufPtr */
- ETInitBufPtr(void *param1)
- {
- asm {
- LEA bufptrs,A0 return where we store bufinfo record pointer
- MOVE.L 4(SP),D0
- MOVE.L D0,0(A0)
- RTS
- }
- } /* End ETInitBufPtr */
-
- /*ETListen */
- ETListen()
- {
- asm {
- LEA DEAF,A5
- TST.W 0(A5)
- BEQ.s Hearing Not deaf, keep going
-
- BRA.S RecvFail Deaf, skip over
-
- ; _Debugger
- ; MOVEQ #0,D3
- ; MOVE.W D3,0(A5) Resume hearing
- ; MOVE.L bufptrs,A5 base for pointers
- ; MOVE.L buforg(A5),D2
- ; MOVE.L D2,bufread(A5) Set to beginning of buffer
- ; MOVE.L D2,bufpt(A5) ditto
- ; MOVE.W D3,bufbig(A5) pretend nothing is in buffer
- ;fall through to hearing
- Hearing
- MOVE.W ETtype(A3),D0 Ok, this is our type
- Got_Prot ;Left in for historical purposes
- CMPI.W #ET_IP,D0
- BEQ.S GoodProt
- CMPI.W #ET_RARP,D0
- BEQ.S GoodProt
- CMPI.W #ET_ARP,D0
- BNE.s RecvFail Well, I only want these......
- GoodProt
- MOVE.L bufptrs,A5
- MOVE.L bufpt(A5),A2
- MOVE.W bufbig(A5),D2
- CMP.W buflim(A5),D2 Used to be CMP.L (6/15/89 - TK)
-
- BGE.S GoDeaf Im full. More = tummy ache
-
- MOVE.L A2,D2 Save it for later (post ReadRest)
- ADDA #dLAYER,A2
- MOVE.W D0,IPProt(A2) Move the protocol into the header
- MOVE.L ETaddr1(A3),ETaddr1(A2) Ok, move the header
- MOVE.L ETaddr2(A3),ETaddr2(A2) One piece at a time
- MOVE.L ETaddr3(A3),ETaddr3(A2) Are we having fun?
- MOVE.W D1,IPLen(A2) Move the suggested retail length into the header
- MOVE.W D1,D3 We need to know if we read the right amount
- MOVEA.L A2,A3
- JSR 2(A4) Read Rest Now
-
- TST.W D3 If this is zero we are OK
- BNE.s SRoll This is bad
- MOVE.L bufptrs,A0
- MOVE.L A3,D3
- MOVE.L D3,D1 Our Temporary Space
- SUB.L D2,D1 D2 was the previous A3
- ADD.W D1,bufbig(A0) Now increment bufbig
- ADDQ.L #1,D3 And Adjust for even/odd buffering
- BCLR #0,D3
-
- CMP.L bufend(A0),D3 Check for Wraparound on end of buffer
- BLE.S UpdatePt
- MOVE.L buforg(A0),D3
- UpdatePt
- MOVE.L D3,bufpt(A0) And Update Buf Pointer
- RTS Terminate (one way or another)
- RecvFail
- MOVEQ #0,D3 Trash the packet
- JMP 2(A4)
-
- GoDeaf
- MOVEQ #1,D3
- LEA DEAF,A5
- MOVE.W D3,0(A5)
- BRA.s RecvFail
-
- UnDeaf
- MOVEQ #0,D3 Be Careful A5 used here
- LEA DEAF,A5
- MOVE.W D3,0(A5)
- RTS
-
- SRoll
- LEA badrecv,A0
- ADDQ.L #1,0(A0)
- RTS
- }
- } /* End ETListen */
-
- /*
- ENDPROC
-
- END
- */
- /***********************************************************************************
- listener.a
- ************************************************************************************/
- /*; The NCSA Socket Listener. For use with NCSA's TCP/IP Implementation
- ; developed in 1986 by Tim Krauskopf and Gaige Paulsen.
- ;
- ; The Socket Listener is passed as a parameter to the DDPOpen Call for
- ; AppleTalk. At this time, all packets received for that socket are passed
- ; to said socket listener instead of causing events.
- ;
- ;
- ; dLAYER changed to add more padding (gotta make it enet size, y'know
- ;
- blanks off
- case on
- */
- /**** Should I make all of these #defines? *****/
-
- /*#define AB_IP_Socket 72 defined above */
- #define toRHA -5
- #define shortDDP 1
- #define lapType 8
- #define lapHdSz 3
- #define sDDPType 10
- #define ddpType 18
- #define AB_IP 22
- #define AB_ARP 23
- /*#define dLAYER 14 defined above, renamed below */
- /*#define IPProt -4 defined above, renamed below */
- /*#define IPLen -14 defined above, renamed below */
- #define AB_dLAYER 14
- #define AB_IPProt -4
- #define AB_IPLen -14
- /*#define bufpt 0 defined above */
- /*#define bufread 4 defined above */
- /*#define buforg 8 defined above */
- /*#define bufend 12 defined above */
- /*#define bufbig 16 defined above */
- /*#define buflim 18 defined above */
-
- /* These are just the old ones */
- AB_IP_Socket EQU 72
- toRHA EQU -5
- shortDDP EQU 1
- lapType EQU 8
- lapHdSz EQU 3
- sDDPType EQU 10
- ddpType EQU 18
- AB_IP EQU 22
- AB_ARP EQU 23
- dLAYER EQU 14 Get the size from C please!
- IPProt EQU -4
- IPLen EQU -14 I Think
- bufpt EQU 0
- bufread EQU 4
- buforg EQU 8
- bufend EQU 12
- bufbig EQU 16
- buflim EQU 18
- /*;
- ;
- ; PUBLIC _Listen,_InitBufPtr
-
- ATnastyhack PROC EXPORT
-
- DEAF DC.W 0
- bufptrs DC.L 0
- badrecv DC.L 0
-
- EXPORT Listen
- EXPORT InitBufPtr
- */
- /*InitBufPtr */
- InitBufPtr(void *param1)
- {
- asm {
- LEA bufptrs,A0
- MOVE.L 4(SP),D0
- MOVE.L D0,0(A0)
- RTS
- }
- } /* End InitBufPtr */
-
-
- /*Listen */
- Listen()
- {
- asm {
- LEA DEAF,A5
- TST.W 0(A5)
- BNE.s RecvFail
- Hearing
- CMPI.B #AB_IP_Socket,D0 Is it for me?
- BEQ.S MySocket Yep
- BRA.S RecvFail No Throw it out!
- MySocket
- LEA toRHA(A2),A3 a3 now is LAP Header
- CMPI.B #shortDDP,lapType(A3)
- ADDQ.L #lapHdSz,A3
- BNE.S LongDDP
- MOVE.B sDDPType(A3),D0 D0 = protocol type
- BRA.S Got_Prot Ive got it
- LongDDP
- MOVE.B ddpType(A3),D0
- Got_Prot
- CMPI.B #AB_IP,D0
- BEQ.S GoodProt
- CMPI.B #AB_ARP,D0
- BNE.S RecvFail
- GoodProt
- MOVE.L bufptrs,A5
- MOVE.L bufpt(A5),A3
- MOVE bufbig(A5),D2
- CMP.L buflim(A5),D2
- BGE.S GoDeaf Im full. More = tummy ache
-
- MOVE.L A3,D2 Save it for later (post ReadRest)
- ADDA #AB_dLAYER,A3
- MOVE.B D0,AB_IPProt(A3) Move the protocol into the header
- MOVE.W D1,AB_IPLen(A3) Move the suggested retail length into the header
- MOVE.W D1,D3 We need to know if we read the right amount
- JSR 2(A4) Read Rest Now
-
- TST.W D3 If this is zero we are OK
- BNE.s BadPkt This is bad
- MOVE.L bufptrs,A0
- MOVE.L A3,D3
- MOVE.L D3,D1 Our Temporary Space
- SUB.L D2,D1 D2 was the previous A3
- ADD.W D1,bufbig(A0) Now increment bufbig
- ADDQ.L #1,D3 And Adjust for even/odd buffering
- BCLR #0,D3
-
- CMP.L bufend(A0),D3 Check for Wraparound on end of buffer
- BLE.S UpdatePt
- MOVE.L buforg(A0),D3
- UpdatePt
- MOVE.L D3,bufpt(A0) And Update Buf Pointer
- RTS Terminate (one way or another)
- RecvFail
- MOVEQ #0,D3 Trash the packet
- JMP 2(A4)
-
- GoDeaf
- MOVEQ #1,D3
- LEA DEAF,A5
- MOVE.W D3,0(A5)
- BRA.s RecvFail
-
- UnDeaf
- MOVEQ #0,D3 Be Careful A5 used here
- LEA DEAF,A5
- MOVE.W D3,0(A5)
- RTS
-
- BadPkt
- LEA badrecv,A0
- ADDQ.L #1,0(A0)
- RTS
- }
- } /* End InitBufPtr */
- /* ENDPROC
-
- END
- */